const fs = require('fs');
const path = require('path');
const postcss = require('postcss');
const tailwindcss = require('@tailwindcss/postcss');
const autoprefixer = require('autoprefixer');

// 源CSS文件路径
const inputFile = path.resolve(__dirname, 'src/styles/tailwind-input.css');
// 输出CSS文件路径
const outputFile = path.resolve(__dirname, 'dist/markdown-renderer.css');

// 确保输出目录存在
if (!fs.existsSync(path.dirname(outputFile))) {
  fs.mkdirSync(path.dirname(outputFile), { recursive: true });
}

// 读取输入CSS文件
const css = fs.readFileSync(inputFile, 'utf8');

// 使用PostCSS处理CSS
postcss([
  tailwindcss('./tailwind.config.js'),
  autoprefixer(),
])
  .process(css, { from: inputFile, to: outputFile })
  .then((result) => {
    // 将处理后的CSS写入输出文件
    fs.writeFileSync(outputFile, result.css);
    console.log(`✅ CSS 已生成到: ${outputFile}`);
  })
  .catch((error) => {
    console.error('❌ CSS 生成失败:', error);
  }); 